/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     Mcu_Extend.c                                                                            *
 * \brief    AUTOSAR 4.3.1 MCAL Mcu Driver                                                             *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/02     <td>1.0.0                               *
 * </table>                                                                                             *
 *******************************************************************************************************/


#ifdef __cplusplus
extern "C" {
#endif
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "McuExt.h"
#include "__regs_base.h"
#include "RegHelper.h"
#include "McuExt_Types.h"
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif /**#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)*/
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
#include "FuSaMcalReportError.h"
#endif /**#if (MCUEXT_SAFETY_ENABLE == STD_ON)*/

/********************************************************************************************************
 *                                 Private Macro definition                                             *
 *******************************************************************************************************/
#if (MCUEXT_PVT_SENSOR_ENABLE == STD_ON)
/** \brief  Get module initialize state. */
#define McuExt_PvtIsInitialized()                             (MCUEXT_PVT_INIT == McuExt_PvtInitializeState)
#endif /** #if (MCUEXT_PVT_SENSOR_ENABLE == STD_ON) */

#if ((MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) || (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON))
/** \brief  Get module initialize state. */
#define McuExt_VdIsInitialized(id)                              (VD_INIT == McuExt_VdController[id].vdStatus)

/** \brief  Get module config pointer. */
#define MCUEXT_VD_GET_CONFIGPTR(id)                               (&McuExt_VdController[id])
#endif /** #if ((MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) || (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON)) */

/********************************************************************************************************
 *                                    Private Type Declarations                                         *
 *******************************************************************************************************/

/********************************************************************************************************
 *                                  Global Variable Declarations                                        *
 *******************************************************************************************************/
#define MCUEXT_START_SEC_VAR_CLEARED_UNSPECIFIED
#include "McuExt_MemMap.h"
#if (MCUEXT_PVT_SENSOR_ENABLE == STD_ON)
uint8 McuExt_PvtInitializeState;
#endif /** #if (MCUEXT_PVT_SENSOR_ENABLE == STD_ON) */

#if ((MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) || (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON))

MCUEXT_LOCAL McuExt_VdControllerType McuExt_VdController[VD_NUM];

#endif /** #if ((MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) || (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON)) */
#define MCUEXT_STOP_SEC_VAR_CLEARED_UNSPECIFIED
#include "McuExt_MemMap.h"

#define MCUEXT_START_SEC_CODE
#include "McuExt_MemMap.h"
/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
#if (MCUEXT_PVT_SENSOR_ENABLE == STD_ON)
/** *****************************************************************************************************
 * \brief This function enable temperature monitor.
 *
 * \verbatim
 * Syntax             : void McuExt_PvtInit(const McuExt_PvtAlarmConfigType *configPtr)
 *
 * Service ID[hex]    : 0x00U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *
 * Description        : This function enable temperature monitor.
 * \endverbatim
 * Traceability       : SWSR_MCU_051 SW_SM001
 *******************************************************************************************************/
void McuExt_PvtInit(const McuExt_PvtAlarmConfigType *configPtr)
{
    Std_ReturnType errorId;

    if (McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_PVT_INIT;
    }
    else if (NULL_PTR == configPtr)
    {
        errorId = MCUEXT_E_PARAM_POINTER;
    }
    else
    {
        errorId = McuExt_Ip_PvtInit(configPtr);

        if (E_OK == errorId)
        {
            McuExt_PvtInitializeState = MCUEXT_PVT_INIT;
        } /* else not needed */
    }

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_PVT_INIT,
                              errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_PVT_INIT,
                                   errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
}

/** *****************************************************************************************************
 * \brief This function get temperature value.
 *
 * \verbatim
 * Syntax             : Std_ReturnType McuExt_PvtGet(float32 *temperaturePtr)
 *
 * Service ID[hex]    : 0x01U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : devPtr - pointer to pvt device
 *
 * Parameters (inout) : temperaturePtr - pointer to pvt value
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *
 * Description        : This function get temperature value.
 *                      Temperature value is not ready until 280ms after McuExt_PvtInit() is called.
 * \endverbatim
 * Traceability       : SWSR_MCU_051 SW_SM001
 *******************************************************************************************************/
Std_ReturnType McuExt_PvtGet(float32 *temperaturePtr)
{
    Std_ReturnType errorId;

    if (!McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else if (NULL_PTR == temperaturePtr)
    {
        errorId = MCUEXT_E_PARAM_POINTER;
    }
    else
    {
        errorId = McuExt_Ip_PvtGet(temperaturePtr);
    } /* else not needed */

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_PVT_GET,
                              errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_PVT_GET,
                                   errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
    return errorId;
}

/** *****************************************************************************************************
 * \brief This function deinit pvt for disable all alarm in all channel.
 *
 * \verbatim
 * Syntax             : Std_ReturnType McuExt_PvtDeinit(void)
 *
 * Service ID[hex]    : 0x02U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : devPtr - pointer to pvt device
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function deinit pvt for disable all alarm in all channel.
 *                      temperature can get.
 * \endverbatim
 * Traceability       : SWSR_MCU_051 SW_SM001
 *******************************************************************************************************/
Std_ReturnType McuExt_PvtDeinit(void)
{
    Std_ReturnType errorId = E_OK;

    if (!McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else
    {
        McuExt_Ip_PvtDeinit();
    } /* else not needed */

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                              MCUEXT_SID_PVT_DEINIT, errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                                   MCUEXT_SID_PVT_DEINIT, errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
    return errorId;
}

/** *****************************************************************************************************
 * \brief This function stop pvt.
 *
 * \verbatim
 * Syntax             : Std_ReturnType McuExt_PvtStop(void)
 *
 * Service ID[hex]    : 0x03U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : devPtr - pointer to pvt device
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function stop pvt.temperature can not get.
 * \endverbatim
 * Traceability       : SWSR_MCU_051 SW_SM001
 *******************************************************************************************************/
Std_ReturnType McuExt_PvtStop(void)
{
    Std_ReturnType errorId = E_OK;

    if (!McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else
    {
        McuExt_Ip_PvtStop();
    } /* else not needed */

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                              MCUEXT_SID_PVT_STOP, errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                                   MCUEXT_SID_PVT_STOP, errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
    return errorId;
}

/** *****************************************************************************************************
 * \brief This function clear alarm status according to channel and alarm type for pvt.
 *
 * \verbatim
 * Syntax             : Std_ReturnType McuExt_PvtClearStatus(McuExt_PvtChannelIdType channel,
                                     McuExt_PvtAlarmType alarm)
 *
 * Service ID[hex]    : 0x04U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : devPtr - pointer to pvt device
 *                      channel - channel id
 *                      alarm - alarm type
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function clear alarm status according to channel and alarm type for pvt.
 * \endverbatim
 * Traceability       : SWSR_MCU_051 SW_SM001
 *******************************************************************************************************/
Std_ReturnType McuExt_PvtClearStatus(McuExt_PvtChannelIdType channel,
                                     McuExt_PvtAlarmType alarm)
{
    Std_ReturnType errorId = E_OK;

    if (!McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else if (channel >= PVT_CHANNEL_NUMBER)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else if (alarm >= PVT_ALARM_NR)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else
    {
        McuExt_Ip_PvtClearStatus(channel, alarm);
    } /* else not needed */

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                              MCUEXT_SID_PVT_CLEAR_STATUS, errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                                   MCUEXT_SID_PVT_CLEAR_STATUS, errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
    return errorId;
}
/** *****************************************************************************************************
 * \brief This function clear alarm status according to channel and alarm type for pvt.
 *
 * \verbatim
 * Syntax             : boolean McuExt_PvtGetStatus(McuExt_PvtChannelIdType channel, McuExt_PvtAlarmType alarm)
 *
 * Service ID[hex]    : 0x05U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : devPtr - pointer to pvt device
 *                      channel - channel id
 *                      alarm - alarm type
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function clear alarm status according to channel and alarm type for pvt.
 * \endverbatim
 *******************************************************************************************************/
boolean McuExt_PvtGetStatus(McuExt_PvtChannelIdType channel,
                                     McuExt_PvtAlarmType alarm)
{
    Std_ReturnType errorId = E_OK;
    boolean status = FALSE;

    if (!McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else if (channel >= PVT_CHANNEL_NUMBER)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else if (alarm >= PVT_ALARM_NR)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else
    {
        status = McuExt_Ip_PvtGetStatus(channel, alarm);
    } /* else not needed */

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                              MCUEXT_SID_PVT_GET_STATUS, errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                                   MCUEXT_SID_PVT_GET_STATUS, errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
    return status;
}
/** *****************************************************************************************************
 * \brief This function clear alarm status according to channel and alarm type for pvt.
 *
 * \verbatim
 * Syntax             : void McuExt_PvtEnableDisableAlarm(McuExt_PvtChannelIdType channel,
                                     McuExt_PvtAlarmType alarm, boolean enable)
 *
 * Service ID[hex]    : 0x06U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : channel - channel id
 *                      alarm - alarm type
 *                      enable - TRUE:ON,FALSE:OFF
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *                      E_OK for success and others for failure.
 *
 * Description        : This function clear alarm status according to channel and alarm type for pvt.
 * \endverbatim
 * Traceability       : SWSR_MCU_051 SW_SM001
 *******************************************************************************************************/
void McuExt_PvtEnableDisableAlarm(McuExt_PvtChannelIdType channel,
                                     McuExt_PvtAlarmType alarm, boolean enable)
{
    Std_ReturnType errorId = E_OK;

    if (!McuExt_PvtIsInitialized())
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else if (channel >= PVT_CHANNEL_NUMBER)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else if (alarm >= PVT_ALARM_NR)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else
    {
        McuExt_Ip_PvtEnableDisableAlarm(channel, alarm, enable);
    } /* else not needed */

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                              MCUEXT_SID_PVT_ENABLE_DISABLE_INTERRUPT, errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                                   MCUEXT_SID_PVT_ENABLE_DISABLE_INTERRUPT, errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
}
/** *****************************************************************************************************
 * \brief Pvt channel0 irq handler.
 *
 * \verbatim
 * Syntax             : void McuExt_PvtChannel0IrqHandler(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Pvt channel1 irq handler.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
void McuExt_PvtChannel0IrqHandler(void)
{
    McuExt_Ip_PvtIrqHandler(0U);
}
/** *****************************************************************************************************
 * \brief Pvt channel1 irq handler.
 *
 * \verbatim
 * Syntax             : void McuExt_PvtChannel1IrqHandler(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : Pvt channel1 irq handler.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
void McuExt_PvtChannel1IrqHandler(void)
{
    McuExt_Ip_PvtIrqHandler(1U);
}
#endif /** #if (MCUEXT_PVT_SENSOR_ENABLE == STD_ON) */

#if ((MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) || (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON))
/** *****************************************************************************************************
 * \brief This function service to initialize voltage detector.
 *
 * \verbatim
 * Syntax             : void McuExt_VdInit(const McuExt_VdCfgType *configPtr)
 *
 * Service ID[hex]    : 0x07U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *
 * Description        : This function service to initialize voltage detector.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
void McuExt_VdInit(const McuExt_VdCfgType *configPtr)
{
    Std_ReturnType errorId;

    if ((McuExt_VdIsInitialized(VD_SF)) || (McuExt_VdIsInitialized(VD_LP)))
    {
        errorId = MCUEXT_E_VD_INIT;
    }
    else if (NULL_PTR == configPtr)
    {
        errorId = MCUEXT_E_PARAM_POINTER;
    }
    else
    {
#if (MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON)
        errorId = Vd_Init(&McuExt_VdController[VD_SF], &configPtr[VD_SF]);
#endif /* #if (MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) */

#if (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON)
        errorId |= Vd_Init(&McuExt_VdController[VD_LP], &configPtr[VD_LP]);
#endif /* #if (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON) */
    }

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_INIT,
                              errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_INIT,
                                   errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
}

/** *****************************************************************************************************
 * \brief This function service to initialize voltage detector.
 *
 * \verbatim
 * Syntax             : uint32 McuExt_VdGetInterruptStatus(void)
 *
 * Service ID[hex]    : 0x08U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *
 * Description        : This function service to initialize voltage detector.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
uint32 McuExt_VdGetInterruptStatus(McuExt_VdIdType controllerId)
{
    Std_ReturnType errorId = E_OK;
    uint32 interruptStatus = 0xFFFFFFFFU;

    if (controllerId >= VD_NUM)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else if (!McuExt_VdIsInitialized(controllerId))
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else
    {
        interruptStatus = Vd_GetInterruptStatus(MCUEXT_VD_GET_CONFIGPTR(controllerId));
    }

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_GET_INTERRUPT_STATUS,
                              errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_GET_INTERRUPT_STATUS,
                                   errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */

    return interruptStatus;
}

/** *****************************************************************************************************
 * \brief This function service to initialize voltage detector.
 *
 * \verbatim
 * Syntax             : uint32 McuExt_VdGetDynamicStatus(McuExt_VdIdType controllerId)
 *
 * Service ID[hex]    : 0x09U
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *
 * Description        : This function service to initialize voltage detector.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
uint32 McuExt_VdGetDynamicStatus(McuExt_VdIdType controllerId)
{
    Std_ReturnType errorId = E_OK;
    uint32 dynamicStatus = 0xFFFFFFFFU;

    if (controllerId >= VD_NUM)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else if (!McuExt_VdIsInitialized(controllerId))
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else
    {
        dynamicStatus = Vd_GetDynamicStatus(MCUEXT_VD_GET_CONFIGPTR(controllerId));
    }

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_GET_DYNAMIC_STATUS,
                              errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_GET_DYNAMIC_STATUS,
                                   errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */

    return dynamicStatus;
}

/** *****************************************************************************************************
 * \brief This function service to initialize voltage detector.
 *
 * \verbatim
 * Syntax             : void McuExt_VdClearInterruptStatus(McuExt_VdIdType controllerId)
 *
 * Service ID[hex]    : 0x0AU
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Non reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : errorId
 *
 * Description        : This function service to initialize voltage detector.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
void McuExt_VdClearInterruptStatus(McuExt_VdIdType controllerId)
{
    Std_ReturnType errorId = E_OK;

    if (controllerId >= VD_NUM)
    {
        errorId = MCUEXT_E_INVALID_PARAM;
    }
    else if (!McuExt_VdIsInitialized(controllerId))
    {
        errorId = MCUEXT_E_UNINIT;
    }
    else
    {
        Vd_ClearInterruptStatus(MCUEXT_VD_GET_CONFIGPTR(controllerId));
    }

    /* ----- Development Error Report --------------------------------------- */
    /* #90 Report errors if any occurred */
#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE))

    if (E_OK != errorId)
    {
#if (MCUEXT_DEV_ERROR_DETECT == STD_ON)
        (void)Det_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID, MCUEXT_SID_VD_CLEAR_INTERRUPT_STATUS,
                              errorId);
#endif /** if (STD_ON == MCUEXT_DEV_ERROR_DETECT) */
#if (MCUEXT_SAFETY_ENABLE == STD_ON)
        (void)FuSaMcal_ReportError(MCUEXT_MODULE_ID, MCUEXT_INSTANCE_ID,
                                   MCUEXT_SID_VD_CLEAR_INTERRUPT_STATUS,
                                   errorId);
#endif /** if (STD_ON == MCUEXT_SAFETY_ENABLE) */
    }/* else not needed */

#else
    {
        /* #100 Dummy assignment avoid compiler warning */
        MCUEXT_DUMMY_STATEMENT(errorId);
    }
#endif /**#if ((STD_ON == MCUEXT_DEV_ERROR_DETECT) || (STD_ON == MCUEXT_SAFETY_ENABLE)) */
}

/** *****************************************************************************************************
 * \brief VD irq handler.
 *
 * \verbatim
 * Syntax             : void McuExt_VdSFIrqHandler(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : VD irq handler.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
ISR(McuExt_VdSFIrqHandler)
{
    VdHookBegin_Vd_IrqHandler(VD_SF);
    Vd_SFIrqHandler(MCUEXT_VD_GET_CONFIGPTR(VD_SF));
    VdHookEnd_Vd_IrqHandler(VD_SF);
}

/** *****************************************************************************************************
 * \brief VD irq handler.
 *
 * \verbatim
 * Syntax             : void McuExt_VdLPIrqHandler(void)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : VD irq handler.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
ISR(McuExt_VdLPIrqHandler)
{
    VdHookBegin_Vd_IrqHandler(VD_LP);
    Vd_LPIrqHandler(MCUEXT_VD_GET_CONFIGPTR(VD_LP));
    VdHookEnd_Vd_IrqHandler(VD_LP);
}
#endif /** #if ((MCUEXT_VOLTAGE_SF_DETECTION_ENABLE == STD_ON) || (MCUEXT_VOLTAGE_LP_DETECTION_ENABLE == STD_ON)) */

#define MCUEXT_STOP_SEC_CODE
#include "McuExt_MemMap.h"

#ifdef __cplusplus
}
#endif
/* End of file */
